import { ItemData } from "../../resource/info/ItemData";
import { SWFPlayer } from "../../scene/modle/SWFPlayer";
import { ItemConfig } from "../../resource/ItemConfig";
import { ModelUtil } from "../../scene/player/info/ModelUtil";
import { ModelType } from "../../scene/modle/data/ModelType";
import { MountResInfo } from "../../scene/player/info/MountResInfo";
import { MountType } from "../../scene/player/entity/MountType";
import { ActionType } from "../../scene/modle/data/ActionType";
//class MountModelPanel
    
    export  class MountModelPanel /* flash.display.Sprite */
    {
        

        public load(arg1: ItemData): void
        {
            if (!this.moduleSwf) 
            {
                this.moduleSwf = new SWFPlayer();
            }
            this.moduleSwf.loadComplete = this.onModuleLoadCompleteHandler;
            var loc1=ItemConfig.instance.getInfoByCode(arg1.itemCode);
            if (arg1.itemExInfo) 
            {
                this.moduleSwf.load(ModelUtil.getModelSWF(arg1.itemExInfo.model_id), ModelType.Mount, new MountResInfo(arg1.itemExInfo.model_id));
            }
            else 
            {
                this.moduleSwf.load(ModelUtil.getModelSWF(loc1.modelId), ModelType.Mount, loc1);
            }
            if (this.contains(this.moduleSwf) == false) 
            {
                this.addChild(this.moduleSwf);
            }
            return;
        }

        /* internal  */onModuleLoadCompleteHandler(arg1: SWFPlayer): void
        {
            var loc1=0;
            this.moduleSwf.loadComplete = null;
            if (this.moduleSwf.movieClipData.modleType != MountType.Rest) 
            {
                if (this.moduleSwf.movieClipData.modleType != MountType.Fly) 
                {
                    if (this.moduleSwf.url == "37015100.swf" || this.moduleSwf.url == "37016100.swf" || this.moduleSwf.url == "47015100.swf" || this.moduleSwf.url == "47016100.swf") 
                    {
                        this.moduleSwf.sceneX = 0;
                        this.moduleSwf.sceneY = 40;
                    }
                    else 
                    {
                        this.moduleSwf.sceneY = 0;
                        this.moduleSwf.sceneX = 0;
                    }
                    loc1 = ActionType.MountStand;
                    this.moduleSwf.updateFrame(loc1, 8, true);
                    this.moduleSwf.updateCurrentFrame(0);
                }
                else 
                {
                    if (this.moduleSwf.url == "37037400.swf" || this.moduleSwf.url == "37037500.swf") 
                    {
                        this.moduleSwf.sceneY = this.moduleSwf.movieClipData.pointY / 2 + 120;
                        this.moduleSwf.sceneX = Math.abs(this.moduleSwf.width - 210) / 2 - 10;
                    }
                    else if (this.moduleSwf.url != "37038500.swf") 
                    {
                        this.moduleSwf.sceneY = this.moduleSwf.movieClipData.pointY / 2 + 70;
                        this.moduleSwf.sceneX = Math.abs(this.moduleSwf.width - 210) / 2 - 10;
                    }
                    else 
                    {
                        this.moduleSwf.sceneY = this.moduleSwf.movieClipData.pointY / 2;
                        this.moduleSwf.sceneX = Math.abs(this.moduleSwf.width - 210) / 2 - 30;
                    }
                    loc1 = ActionType.flyMountStand;
                    this.moduleSwf.updateFrame(loc1, 8, true);
                    this.moduleSwf.updateCurrentFrame(0);
                }
            }
            else 
            {
                if (this.moduleSwf.url != "37041100.swf") 
                {
                    this.moduleSwf.sceneY = this.moduleSwf.movieClipData.pointY / 2 + 90;
                    this.moduleSwf.sceneX = Math.abs(this.moduleSwf.width - 210) / 2;
                }
                else 
                {
                    this.moduleSwf.sceneY = this.moduleSwf.movieClipData.pointY / 2 - 32;
                    this.moduleSwf.sceneX = Math.abs(this.moduleSwf.width - 210) / 2 - 35;
                }
                loc1 = ActionType.RestMountStand;
                this.moduleSwf.updateFrame(loc1, 8, true);
                this.moduleSwf.updateCurrentFrame(0);
            }
            this.moduleSwf.play();
            return;
        }

        public clear(): void
        {
            if (this.moduleSwf) 
            {
                if (contains(this.moduleSwf)) 
                {
                    removeChild(this.moduleSwf);
                }
                this.moduleSwf.loadComplete = null;
                this.moduleSwf.dispose();
                this.moduleSwf = null;
            }
            return;
        }

        public /* var */moduleSwf: SWFPlayer;
    }
